//声明 add 的函数
function add(a: number, b: number):number{
  return a + b;
}

//匿名函数赋值
let sub = function(a: number, b: number): number{
  return a - b;
}

//箭头函数
let times = (a: number, b: number):number => {
  return a * b;
}

// console.log(add(1,2));
//先声明函数的类型, 再为函数赋值
let divide: (a:number, b:number) => number;
divide = (a, b) => {
  return a / b;
}

//既声明 又赋值
let yu: (a:number, b:number) => number = (a, b) => {
  return a % b;
};

//不写返回值类型
let pow = (a:number,b:number) => {
  return Math.pow(a, b);
}

//声明一个函数 字符串截取  ''.slice()
function slice(str: string, start: number, end ?: number){

}
slice('iloveyou', 1, 5);
slice('iloveyou', 1);


//函数形参的默认值   类型注解
function buildPhone(str: string, area: string='+86'){
  console.log(area);
}

buildPhone('15845963587', '+158');
buildPhone('15845963587'); 

// rest 参数  arguments 获取实参列表
function jia(a: number, ...args:number[]){
  console.log(args); 
}

jia(1,2,3,4,5);
